import json

from credit_voice_service.dialogue.factory.base_info.strategy.base_info_strategy_2144 import BaseInfoStrategy2144
from credit_voice_service.dialogue.factory.base_info.strategy.base_info_strategy_2148 import BaseInfoStrategy2148
from credit_voice_service.dialogue.factory.base_info.strategy.base_info_strategy_2132 import BaseInfoStrategy2132
from credit_voice_service.dialogue.factory.base_info.strategy.base_info_strategy_fallback import \
    BaseInfoStrategyFallback


class BaseInfoFactory:
    def get_base_info_strategy(self, session_id):
        try:
            if session_id:
                data = session_id.split('-')
                company_id = data[1]
                if '2144' == company_id:
                    return BaseInfoStrategy2144()
                elif '2148' == company_id:
                    return BaseInfoStrategy2148()
                elif '2132' == company_id:
                    return BaseInfoStrategy2132()
                else:
                    return BaseInfoStrategyFallback()
        except Exception:
            return BaseInfoStrategyFallback()


class SuperMarket:
    def __init__(self, f_obj):  # 参数: 工厂对象
        self.f_obj = f_obj

    def sale_base_info_strategy(self, session_id):
        return self.f_obj.get_base_info_strategy(session_id)


class BaseInfoData:

    def get_base_info_data(self, session_id, user_info):
        f = BaseInfoFactory()
        base_info_class = SuperMarket(f)
        base_info_strategy = base_info_class.sale_base_info_strategy(session_id)
        return base_info_strategy.get_base_info(session_id, user_info)


if __name__ == '__main__':
    # base = BaseInfoData()
    # data = base.get_base_info_data('123', '0', '')
    # print(data)
    pass
